$(function(){
	this.$body = $('.gray-bg');
	//[data-setstatus]
	this.$body.on('click','[data-setstatus]',function(){
	    action = this.getAttribute("data-setstatus");
	    param = JSON.stringify( this.getAttribute("data-param").split(",") );
	    $.post(action,{param:param},function(res){ response(res); });
	});

	//[data-upload]
	this.$body.on('click','[data-upload]',function(){
		multiple = this.getAttribute("data-multiple");
		targetpath = this.getAttribute("data-upload");
		action = this.getAttribute("data-action");
		data_ext = this.getAttribute("data-ext");
	    var url = '/admin/attachment/uploadfile?multiple='+multiple+'&targetpath='+targetpath+'&action='+action+'&data_ext='+data_ext;
		layer.open({
			type:2,
			title:"上传附件",
			area:['80%','50%'],
			content:url,
			btn:['确定'],
			yes:function(){
				window.location.reload();
			},
			cancel:function(){
				window.location.reload();
			}
		});
	});

	//[data-delete]
	this.$body.on('click','[data-delete]',function(){
	    action = this.getAttribute("data-delete");
	    param = JSON.stringify( this.getAttribute("data-param").split(",") );
	    if(param == ''){
	    	layer.msg('请选择数据');
	    }else{
	    	layer.open({
		    	type:1,
		    	title:"提示",
		    	content:'<div class="alert alert-danger" role="alert">确认删除这些数据吗?</div>',
		    	btn:['确认','取消'],
		    	yes:function(){
		    		$.post(action,{param:param},function(res){
		    			layer.closeAll();
		    			response(res);
		    		});
		    	},
		    	btn2:function(){
		    		layer.closeAll();
		    	}
		    })
	    }
	});
})

function response(res){
	if(res.code == 1){
		callbackSuccess(res);
	}else{
		callbackError(res);
	}
}

function callbackSuccess(res){
	$('#stop-opration').css({'display':'block'});
    layer.msg(res.msg);
    setTimeout(function(){
        window.location.reload();
    },600);
}
function callbackError(res){
    layer.msg(res.msg);
}